package LeetCode._02_数组;

public class _560_和为K的子数组 {
    private int[] preSum;
    public int subarraySum(int[] nums, int k) {
        if(nums == null || nums.length == 0) return 0;
        preSum = new int[nums.length+1];
        for(int i=1;i< preSum.length;i++){
            preSum[i] = preSum[i - 1] + nums[i-1];
        }
        int res = 0;
        for(int i=1;i< preSum.length;i++){
            for(int j=0;j<i;j++){
                if(preSum[i] - preSum[j] == k){
                    res++;
                }
            }
        }
        return res;
    }
}
